import { http } from '~/utils/request'

import api from '@/config/api'

// 获取验证code
export const getVerifyCode = `${api.common}/common/slider`

// 扫码登录
export function scannerCodeLoginConfirm(params: any) {
  return http.request({
    url: '/passport/member/app_confirm',
    method: 'POST',
    params
  })
}

// 设置支付密码
export function setPassword(params: any) {
  return http.request({
    url: `/wallet/wallet/set-password`,
    method: 'POST',
    params
  })
}

export function scannerCodeLogin(params: any) {
  return http.request({
    url: '/passport/member/app_scanner',
    method: 'POST',
    params
  })
}

/**
 * web 第三方登录
 * @param {Object} code
 */
export function webConnect(code: string) {
  return http.request({
    url: `passport/connect/connect/login/web/${code}`,
    method: 'GET',
    header: {
      clientType: 'H5'
    }
  })
}

export function openIdLogin(params: any, clientType: string) {
  return http.request({
    url: `passport/connect/connect/app/login`,
    method: 'POST',
    data: params,
    header: {
      clientType: clientType
    }
  })
}

/**
 * 小程序自动登录
 * @param params
 */
export function mpAutoLogin(params: any) {
  return http.request({
    url: 'passport/connect/mini-program/auto-login',
    method: 'GET',
    params
  })
}

// 校验支付密码是否正确
export function isCheckPassword(params: any) {
  return http.request({
    url: `/wallet/wallet/check/password`,
    method: 'GET',
    params
  })
}

// 校验是否设置支付密码
export function checksetUpPassword() {
  return http.request({
    url: `/wallet/wallet/check`,
    method: 'GET'
  })
}

// 退出登录
export function logout() {
  return http.request({
    url: '/passport/member/logout',
    method: 'POST'
  })
}

/**
 * 账号密码登陆
 * @params  password
 * @params  username
 */
export function userLogin(params: any) {
  return http.request({
    method: 'POST',
    url: `/passport/member/userLogin`,
    data: params,
    header: {
      'content-type': 'application/x-www-form-urlencoded'
    }
  })
}

/**
 * 发送验证码
 * @param  mobile
 */
export function sendMobile(mobile: string, type = 'LOGIN') {
  return http.request({
    url: `${api.common}/common/sms/${type}/${mobile}`,
    method: 'GET'
  })
}

/**
 * 短信登录
 * @param  mobile
 * @param  smsCode
 */
export function smsLogin(params: any, clientType: string) {
  return http.request({
    url: `/passport/member/smsLogin`,
    method: 'POST',
    data: params,
    header: {
      'content-type': 'application/x-www-form-urlencoded',
      clientType: clientType
    }
  })
}

/**
 * 获取登录信息
 */
export function getUserInfo() {
  return http.request({
    method: 'GET',
    url: `/passport/member`
  })
}

/**
 * 获取登录信息
 */
export function setUserInfo(params: any) {
  return http.request({
    method: 'PUT',
    url: `/passport/member/editOwn`,
    data: params,
    header: { 'content-type': 'application/x-www-form-urlencoded' }
  })
}

/**
 * 刷新token
 * @param {*} token
 * @returns
 */
export function refreshTokenFn(token: string | unknown) {
  return http.request({
    url: `/auth/refresh/${token}`,
    method: 'GET'
  })
}

/**
 * 小程序自动登录
 * @param params
 */
export function openIdBind(params: any) {
  return http.request({
    url: '/passport/connect/bind',
    method: 'POST',
    params
  })
}

export function combineLogin(params: any) {
  return http.request({
    url: '/passport/connect/mini-program/combine-login',
    method: 'POST',
    data: params
  })
}
